{include file="public/header" /}
<link rel="stylesheet" type="text/css" media="all" href="/sldate/daterangepicker-bs3.css" />
<script type="text/javascript" src="/sldate/moment.js"></script>
<script type="text/javascript" src="/sldate/daterangepicker.js"></script>
<link rel="stylesheet" type="text/css" href="/static/admin/webupload/webuploader.css">
<link rel="stylesheet" type="text/css" href="/static/admin/webupload/style.css">
<script type="text/javascript">
    $(document).ready(function() {
        $('#reservation').daterangepicker(null, function(start, end, label) {
            console.log(start.toISOString(), end.toISOString(), label);
        });
    });
</script>
<style>
    .file-item{float: left; position: relative; width: 110px;height: 110px; margin: 0 20px 20px 0; padding: 4px;}
    .file-item .info{overflow: hidden;}
    .uploader-list{width: 100%; overflow: hidden;}
</style>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>添加广告</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                        <a class="dropdown-toggle" data-toggle="dropdown" href="form_basic.html#">
                            <i class="fa fa-wrench"></i>
                        </a>
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <form class="form-horizontal m-t" name="add" id="add" method="post" action="add_letter">
                        {if condition="$instit_id==1"}


                        {else}
                                {if condition="$instit_info.type==1"}
                        <div class="form-group">
                            <label class="col-sm-3 control-label">发送对象：</label>
                            <div class="input-group col-sm-4">
                                <!--<input id="" type="text" class="form-control" name="title" placeholder="请输入广告标题">-->
                                <select name="type" id="type" class="form-control">
                                    <option value="0">全体机构成员</option>
                                    <option value="1">个人</option>
                                    <option value="2">教师</option>
                                    <option value="3">班主任</option>
                                </select>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">成员名称：</label>
                            <div class="input-group col-sm-4">
                                <!--<input id="" type="text" class="form-control" name="title" placeholder="请输入广告标题">-->
                                <select name="user_id" id="user_id" class="form-control">
                                    <option value="0">请选择</option>
                                    {foreach name="members" item="val"}
                                    <option value="{$val.id}">{$val.nickname}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                                {/if}

                                {if condition="$instit_info.type==2"}
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">发送对象：</label>
                                        <div class="input-group col-sm-4">
                                            <!--<input id="" type="text" class="form-control" name="title" placeholder="请输入广告标题">-->
                                            <select name="type" id="type" class="form-control">
                                                <option value="0">全体机构成员</option>
                                                <option value="1">机构个人</option>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">成员名称：</label>
                                        <div class="input-group col-sm-4">
                                            <!--<input id="" type="text" class="form-control" name="title" placeholder="请输入广告标题">-->
                                            <select name="user_id" id="user_id" class="form-control">
                                                <option value="0">请选择</option>
                                                {foreach name="members" item="val"}
                                                    <option value="{$val.id}">{$val.nickname}</option>
                                                {/foreach}

                                            </select>
                                        </div>
                                    </div>


                                {/if}
                        {/if}



                        <div class="form-group">
                            <label class="col-sm-3 control-label">标题：</label>
                            <div class="input-group col-sm-4">
                                <input id="title" type="text" class="form-control" name="title" placeholder="请输入广告标题">
                            </div>
                        </div>

                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label " for="myEditor">内容：</label>
                            <div class="input-group col-sm-9">
                                <script src="/static/admin/ueditor/ueditor.config.js" type="text/javascript"></script>
                                <script src="/static/admin/ueditor/ueditor.all.js" type="text/javascript"></script>
                                <textarea name="content" style="width:90%" id="myEditor"></textarea>
                                <script type="text/javascript">
                                    var editor = new UE.ui.Editor();
                                    editor.render("myEditor");
                                </script>
                            </div>
                        </div>

                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-3">
                                <button class="btn btn-primary" type="submit"><i class="fa fa-save"></i> 保存信息</button>&nbsp;&nbsp;&nbsp;
                                <a class="btn btn-danger" href="javascript:history.go(-1);"><i class="fa fa-close"></i> 返回</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}

<script type="text/javascript" src="/static/admin/webupload/webuploader.min.js"></script>


<script type="text/javascript">

    $(function(){
        $('#add').ajaxForm({
            beforeSubmit: checkForm, // 此方法主要是提交前执行的方法，根据需要设置
            success: complete, // 这是提交后的方法
            dataType: 'json'
        });

        function checkForm(){
            if( '' == $.trim($('#title').val())){
                layer.msg('标题不能为空', {icon: 5}, function(index){
                    layer.close(index);
                });
                return false;
            }

        }

        function complete(data){
            if(data.code == 1){
                layer.msg(data.msg, {icon: 6,time:1500,shade: 0.1}, function(index){
                    layer.close(index);
                    window.location.href="{:url('Letter/index')}";
                });
            }else{
                layer.msg(data.msg, {icon: 5,time:1500,shade: 0.1}, function(index){
                    layer.close(index);
                });
                return false;
            }
        }

    });


    //IOS开关样式配置
    var elem = document.querySelector('.js-switch');
    var switchery = new Switchery(elem, {
        color: '#1AB394'
    });
    var config = {
        '.chosen-select': {},
    }
    for (var selector in config) {
        $(selector).chosen(config[selector]);
    }


</script>
</body>
</html>
